﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SimulationHW2
{
    public partial class OutPutSimulation : Form
    {
        public OutPutSimulation( )
        {
            InitializeComponent();
        }
        private double fCalculated;
        private double k1;
        private double k2;
        private double fTable;
        private string[] strResult;
        private double regression;
        private string[] str;

        public void ShowOutPut(double fCalculated, double k1, double k2, string[] strResult,
            double regression)
        {
            this.fCalculated = fCalculated;
            this.k1 = k1;
            this.k2 = k2;
            this.strResult = strResult;
            this.regression = regression;
            lblOutPut.Text  = string.Format("Fcalculate: {0}\nFtable (K1: {1},K2: {2}) ", fCalculated, k1, k2);
        }

        public OutPutSimulation(string[] str)
        {
            this.str = str;
        }

        #region Output Simulation

        private void btnCheckF_Click(object sender, EventArgs e)
        {
            if (txtFisherTable.Text != string.Empty)
            {
                fTable = Convert.ToDouble(txtFisherTable.Text);

                if (fCalculated < fTable)
                {
                    textBox1.Enabled = lblResult.Enabled = lblCheckFisher.Enabled = true;
                    lblResult.Text = string.Format("Regression Equation Y^ = {0} and the function:",regression);
                    textBox1.Lines = strResult;
                    lblCheckFisher.BackColor = DefaultBackColor;
                    lblCheckFisher.Text = "Test Fisher Successed";
                }
                else
                {
                    textBox1.Text = lblResult.Text = string.Empty;
                    textBox1.Enabled = lblResult.Enabled = false;
                    lblCheckFisher.BackColor = Color.Red;
                    lblCheckFisher.Text = "Test Fisher Unsuccessfully";
                }
            }
        }

        private void txtFisherTable_KeyPress(object sender, KeyPressEventArgs e)
        {
            //if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(),"^[0-9]+.[0-9]+$"))
            //    e.Handled = true;
        }

        #endregion Output Simulation

        private void button1_Click(object sender, EventArgs e)
        {
            // Show Simulation Tables
            ShowTableSimulation showTableAndSimulation = new ShowTableSimulation();
            showTableAndSimulation.Show();
        }

        /// <summary>
        /// Exit from Output Simulation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OutPutSimulation_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)27)
                this.Close();
        }

    }
}
